<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of wallet
 *
 * @author Bui Van Thien
 */
class Model_Wallet extends \Orm\Model
{

    protected static $_properties = array(
        'id',
        'user_id',
        'name',
        'current_money',
        'earn',
        'spent',
        'created',
        'updated',
        'default'
    );
    
    protected static  $_observer = array(
        'Orm/Observer_CreatedAt'=>array(
          'events'  => array('before_insert'),
          'mysql_timestamp'=>true,
          'property'=>'created'
        ),
        'Orm/Observer_UpdatedAt'=>array(
            'events'=>array('before_save'),
            'mysql_timestamp'=>true,
            'property'=>'updated'
        )
    );
    
    protected static $_table_name = 'wallets';
    
    protected static $_belong_to = array(
        'user' => array(
            'key_from'=>'user_id',
            'model_to'=>'Model_User',
            'key_to'=>'id',
            'cascade_save'=>false,
            'cascade_delete'=>false
        ),
    );
    protected  static $_has_many = array(
        'transaction'=>array(
            'key_from'=>'id',
            'model_to'=>'Model_Transaction',
            'key_to'=>'wallet_id',
            'cascade_save'=>false,
            'cascade_delete'=>true
        ),
    );
}
